/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 2/22/14
 * Time: 3:31 PM
 * To change this template use File | Settings | File Templates.
 */
package com.societyGames.interceptExercises
{
import com.greensock.easing.Sine;
import com.societyGames.action.MoveToAction;

import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;

public class MoveToWithLineAction extends MoveToAction
{
  private var _movingDisplayObject:DisplayObject;
  private var _lineSprite:Sprite;
  private var _startX:Number;
  private var _startY:Number;

  public function MoveToWithLineAction(displayObject:DisplayObject, endX:Number, endY:Number, duration:Number, lineSprite:Sprite, startX:Number, startY:Number)
  {
    super(displayObject, endX, endY, duration, Sine.easeInOut);
    _movingDisplayObject = displayObject;
    _lineSprite = lineSprite;
    _startX = startX;
    _startY = startY;
  }

  override public function startAction():void
  {
    super.startAction();
    _lineSprite.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
  }

  private function handleEnterFrame(event:Event):void
  {
    _lineSprite.graphics.clear();
    _lineSprite.graphics.lineStyle(1, 0xCCCCCC);
    _lineSprite.graphics.moveTo(_startX, _startY);
    _lineSprite.graphics.lineTo(_movingDisplayObject.x, _movingDisplayObject.y);
  }

  override protected function onComplete():void
  {
    _lineSprite.removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
    super.onComplete();
  }
}
}
